// custom-tab-bar/index.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  options: {
    multipleSlots: true, // 在组件定义时的选项中启用多slot支持
    styleIsolation: 'shared' // 组件样式隔离，使用外部样式，但不影响外部样式
  },

  lifetimes: {
    // attached: async function () {
    //   const systemInfo = await wx.pro.getSystemInfo();
    //   setTimeout(() => {
    //     const query = this.createSelectorQuery()
    //     query.select('#tabbar').boundingClientRect(function (res) {
    //       const height = systemInfo.screenHeight - systemInfo.safeArea.bottom + res.height
    //       console.log(height, '123height', systemInfo.screenHeight, systemInfo.safeArea.bottom, res.height);
    //       app.globalData.tabbarHeight = height
    //       console.log(app.globalData, 'app.globalData')
    //     })
    //     query.exec()
    //   },2000)
    // }
    attached: async function () {
      const _this = this
      const systemInfo = await wx.pro.getSystemInfo();
      const num = systemInfo.screenHeight - systemInfo.safeArea.bottom
      const query = this.createSelectorQuery()
      query.select('#tabbar').boundingClientRect(function (res) {
        const data = app.globalData.tabbarHeight
        if (data === 0) {
          const height = systemInfo.screenHeight - systemInfo.safeArea.bottom + res.height
          app.globalData.tabbarHeight = height
        }
      })
      query.exec()
      this.setData({
        paddingNum: num === 0 ? 10 : 20,
        timer: setTimeout(() => {
          _this.getInform()
        }, 10000)
      })
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    paddingNum: 0,
    timer: null,
    color: "#7A7E83",
    selectedColor: "#E6304F",
    nbBackgroundColor: '#E6304F',
    list: [
      {
        url: "/pages/home/index",
        text: "首页",
        icon: 'wap-home-o',
        prefix: 'iconfont icon-home-fill'
      },
      {
        url: "/pages/brief/sideMember/index",
        text: "会员",
        icon: 'flag-o',
        prefix: 'iconfont icon-kehuqunzu'
      },
      {
        url: "/pages/activity/index",
        text: "活动",
        icon: 'flag-o',
        prefix: 'iconfont icon-jiankanghuodong'
      },
      {
        url: "/pages/activity/index",
        text: "商机",
        icon: 'flag-o',
        prefix: 'iconfont icon-mn_dianpu_fill'
      },
      {
        url: "/pages/my/index",
        text: "我的",
        icon: 'contact',
        prefix: 'iconfont icon-wode',
        info: 1
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
		onChange(event) {
			this.setData({ active: event.detail });
			wx.switchTab({
				url: this.data.list[event.detail].url
			});
		},

		init() {
			const page = getCurrentPages().pop();
			this.setData({
				active: this.data.list.findIndex(item => item.url === `/${page.route}`)
			});
    }
	}
})
